package com.test.thread;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class Temp {
    private static Map<String, String> map = new HashMap<>();
    static {
        map.put(")", "(");
        map.put("]", "[");
        map.put("}", "{");
    }

    public static boolean check(String target){
        char[] targets = target.toCharArray();
        Stack<Character> stack = new Stack<>();
        for(char c : targets){
            if(map.keySet().contains(String.valueOf(c))){
                Character popc = stack.isEmpty() ? '#' : stack.pop();
                if(!map.get(String.valueOf(c)).equals(String.valueOf(popc))){
                    return false;
                }
            }else{
                stack.push(c);
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        String s1 = "([])";
        System.out.println(check(s1));
        String s2 = "([{]})";
        System.out.println(check(s2));
    }
}
